package com.example.ioc.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class PropertiesLoader {

    public static Properties loadProperties() {
        //获取文件流
        InputStream is = PropertiesLoader.class.getClassLoader().getResourceAsStream("application.properties");

        //获取文件的位置
        String filePath = PropertiesLoader.class.getClassLoader().getResource("application.properties").getFile();
        System.out.println(filePath);

        Properties properties = new Properties();
        try {
            properties.load(is);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (null != is) {
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        return properties;
    }

}
